package com.example.carefree_server.mapper.m_loginMapper;

import com.example.carefree_server.entity.Department;
import com.example.carefree_server.entity.Student;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface LoginMapper {

    @Select("select count(*) from student where sid = #{sid} and spassword = #{spassword}")
    int finduser(String sid, String spassword);

    @Select("select count(*) from department where did = #{did} and dpassword = #{dpassword}")
    int finddepartment(String did, String dpassword);

    @Select("select  count(*) from manager where mid = #{mid} and mpassword = #{mpassword}")
    int findemanage(String mid, String mpassword);

    //判断密保（学生）
    @Select("select count(*) from student where sid = #{sid} and text = #{protection1} ")
    int scheckprotection(String sid, String protection1);

    //判断密保（部门）
    @Select("select count(*) from department where did = #{did} and text = #{protection1}")
    int dcheckprotection(String did, String protection1);

    //重置密码（学生）
    @Update("Update student set spassword = #{spassword} where sid = #{sid}")
    int supdatepassword(String sid, String spassword);

    //重置密码（部门）
    @Update("Update department set dpassword = #{dpassword} where did = #{did}")
    int dupdatepassword(String did, String dpassword);

    //重置密保（学生）
    @Update("Update student set problem = #{question1} , text = #{protection1} where sid = #{sid}")
    int supdatepasswordprotection(String sid, String question1, String protection1);

    //重置密保（部门）
    @Update("Update department set problem = #{question1} , text = #{protection1} where did = #{did}")
    int dupdatepasswordprotection(String did, String question1, String protection1);

    //获得学生自定义问题
    @Select("select problem from student where sid = #{sid} ")
    List<Student> selectsquestion1(String sid);

    //获得部门自定义问题
    @Select("select problem from department where did = #{did} ")
    List<Department> selectdquestion1(String did);

    @Select("select count(*) from student where sid = #{sid}")
    int finduserId(String sid);

    @Select("select count(*) from department where did = #{did}")
    int finddepartmentId(String did);

}
